package com.example.logdemo;

import ch.qos.logback.classic.LoggerContext;
import org.slf4j.ILoggerFactory;
import org.slf4j.impl.StaticLoggerBinder;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author cxx
 * @create 2021-02-25 9:38
 **/
@Component
public class InitConfiguration implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        TrackLogConfiguration configuration = new TrackLogConfiguration ();
        LoggerContext loggerContext = getLoggerContext ();
        configuration.setContext (loggerContext);
        configuration.configure (loggerContext);
    }

    private static LoggerContext getLoggerContext(){
        ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
        return (LoggerContext) factory;
    }
}
